/*
 *  $Id: Inscribe.cs 1065 2010-05-20 21:38:46Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using AgateLib.DisplayLib;

namespace Ragima.Cards001.Air.Abilities {
    public class Inscribe: AbilityCard<Affect> {
        public Inscribe(): base("001_a_a_inscribe") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Air;
            Target = new EnchantmentTarget(GetTargetPhrase(), true, IsCreatureAffect);
            AddManaCost(ElementType.Air, 2);
        }

        private static bool IsCreatureAffect(TargetRequest request, Affect affect) {
            return affect.Owner is Creature;
        }

        protected override void DoAction(TargetArgs<Affect> args) {
            args.Caster.RemoveAffect<MagicShatter.MSAffect>();
            args.Caster.RemoveAffect<InscribeAffect>();
            args.Caster.AddAffect(new InscribeAffect(args.Target.Clone()));
        }

        private class InscribeAffect: Affects.AbilityAffect {
            private Affect _affect;

            public InscribeAffect(Affect affect): base(new InscribeCast(affect)) {
                _affect = affect;
            }

            public override bool Dispellable {
                get { return false; }
            }

            public override Affect Clone() {
                return new InscribeAffect(_affect);
            }
        }

        private class InscribeCast: AbilityCard<Creature> {
            private Affect _affect;

            public InscribeCast(Affect affect): base("001_a_a_inscribe_cast") {
                _affect = affect;
                Level = CompleteLevel.ReadyForTest;
                Element = _affect.Element;
                Target = CreatureTarget.Both;
            }

            public override Languages.Phrase Description {
                get { return _affect.Description; }
            }

            public override string DescriptionText {
                get { return _affect.DescriptionText; }
            }

            public override Surface BigPicture {
                get { return _affect.BigPicture; }
            }

            public override Surface SmallPicture {
                get { return _affect.SmallPicture; }
            }

            protected override void DoAction(TargetArgs<Creature> args) {
                args.Caster.DamageBy(NewDamage(args, DamageType.Health, 1));
                args.Target.AddAffect(_affect.Clone());
            }
        }
    }
}
